package com.zh.juc.atomic;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @Author: zhanghuan
 * @date: 2022/10/19 19:23
 * @description: create it
 * <p>
 * 数组类型原子类
 * - AtomicIntegerArray
 * - AtomicLongArray
 * - AtomicReferenceArray

 */
public class AtomicIntegerArrayDemo {
    public static void main(String[] args) {
        // AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(new int[5]);
        AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(5);
        // AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(new int[]{1, 2, 3, 4, 5});
        for (int i = 0; i < atomicIntegerArray.length(); i++) {
            System.out.println(atomicIntegerArray.get(i));
        }
        System.out.println("----------------");
        int temp = 0;
        temp = atomicIntegerArray.getAndSet(0, 2022);
        System.out.println(temp + "\t" + atomicIntegerArray.get(0));

        temp = atomicIntegerArray.getAndIncrement(0);

        System.out.println(temp + "\t" + atomicIntegerArray.get(0));
    }
}
